///Login

function validateLogin()
{
	var returnValue = true;
	var loginForm = document.forms["loginForm"];
	var username = loginForm["username"].value;
	var password = loginForm["password"].value;
	
	var loginTable = document.getElementById("loginTable");
	
	var usernameValidateRow = document.getElementById("usernameValidateRow");
	if (typeof(usernameValidateRow) != 'undefined' && usernameValidateRow != null)
	{
		usernameValidateRow.parentNode.removeChild(usernameValidateRow);
	}
	
	
	var passwordValidateRow = document.getElementById("passwordValidateRow");
	if(typeof(passwordValidateRow) !=  'undefined' && passwordValidateRow != null)
	{
		passwordValidateRow.parentNode.removeChild(passwordValidateRow);
	}

	
	if(username == null | username == "")
	{
		
		var usernameValidateRow = loginTable.insertRow(1);
		usernameValidateRow.id = "usernameValidateRow";
		var usernameValidateCell = usernameValidateRow.insertCell();
		usernameValidateCell.colSpan = "2";
		usernameValidateCell.align = "right";
		usernameValidateCell.className = "loginValidate";
		usernameValidateCell.innerHTML = "Please enter a username";
		returnValue = false;
	}
	
	if(password == null | password == "")
	{
		
		var passwordValidateRow = loginTable.insertRow(-1);
		passwordValidateRow.id = "passwordValidateRow";
		var passwordValidateCell = passwordValidateRow.insertCell();
		passwordValidateCell.colSpan = "2";
		passwordValidateCell.align = "right";
		passwordValidateCell.className = "loginValidate";
		passwordValidateCell.innerHTML = "Please enter a password";
		returnValue = false;
	}
	
	return returnValue;
}

function validateLogin2()
{
	var returnValue = true;
	var loginForm = document.forms["loginForm"];
	var username = loginForm["username"].value;
	var password = loginForm["password"].value;
	
	var usernameInput = document.getElementById("username");
	var passwordInput = document.getElementById("password");
	
	usernameInput.className = "validLogin";
	passwordInput.className = "validLogin";
	
	if(password == null | password == "")
	{
		passwordInput.className = "invalidLogin";
		passwordInput.focus();
		returnValue = false;
	}
	
	if(username == null | username == "")
	{
		usernameInput.className = "invalidLogin";
		usernameInput.focus();
		returnValue = false;
	}
	
	return returnValue;
}

////RegisterPage
	var emailregexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var dateregexp = /^\d{2}([.\/-])\d{2}\1\d{4}$/;
	
	function validateForm()
	{
		var returnValue = true;
		var form = document.forms["registerForm"];
		var date = form["dob"].value;
		var email = form["email"].value;
		var gender = form["gender"];
		var password = form["password"].value;
		var username = form["username"].value;
		var address = form["address"].value;
		var city = form["city"].value;
		var state = form["state"].value;
		var zip = form["zip"].value;
		
		var addressTableRow = document.getElementById("addressTableRow");
		if(addressTableRow.cells.length == 3)
		{
			addressTableRow.deleteCell(-1);
		}
		
		var cityTableRow = document.getElementById("cityTableRow");
		if(cityTableRow.cells.length == 3)
		{
			cityTableRow.deleteCell(-1);
		}
		
		var stateTableRow = document.getElementById("stateTableRow");
		if(stateTableRow.cells.length == 3)
		{
			stateTableRow.deleteCell(-1);
		}
		
		var zipTableRow = document.getElementById("zipTableRow");
		if(zipTableRow.cells.length == 3)
		{
			zipTableRow.deleteCell(-1);
		}
		
		var dobTableRow = document.getElementById("dobTableRow");
		if(dobTableRow.cells.length == 3)
		{
			dobTableRow.deleteCell(-1);
		}
		
		var genderTableRow = document.getElementById("genderTableRow");
		if(genderTableRow.cells.length == 3)
		{
			genderTableRow.deleteCell(-1);
		}
		
		var emailTableRow = document.getElementById("emailTableRow");
		if(emailTableRow.cells.length == 3)
		{
			emailTableRow.deleteCell(-1);
		}
		
		var usernameTableRow = document.getElementById("usernameTableRow");
		if(usernameTableRow.cells.length == 3)
		{
			usernameTableRow.deleteCell(-1);
		}
		
		var passwordTableRow = document.getElementById("passwordTableRow");
		if(passwordTableRow.cells.length == 3)
		{
			passwordTableRow.deleteCell(-1);
		}
		
		if(!dateregexp.test(date))
		{
			var dobValidateTableCell = dobTableRow.insertCell(-1);
			dobValidateTableCell.className = "validate";
			dobValidateTableCell.innerHTML = "Please enter a valid date";
			returnValue = false;
		}
		
		if(gender[0].checked == false && gender[1].checked == false)
		{
			var genderValidateTableCell = genderTableRow.insertCell(-1);
			genderValidateTableCell.className = "validate";
			genderValidateTableCell.innerHTML = "Please select a gender";
			returnValue = false;
		}
		
		if(!emailregexp.test(email))
		{
			var emailValidateTableCell = emailTableRow.insertCell(-1);
			emailValidateTableCell.className = "validate";
			emailValidateTableCell.innerHTML = "Please enter a valid email";
			returnValue = false;
		}

		if(username == null | username == "")
		{
			var usernameValidateTableCell = usernameTableRow.insertCell(-1);
			usernameValidateTableCell.className = "validate";
			usernameValidateTableCell.innerHTML = "Please enter a valid username";
			returnValue = false;
		}

		if(password == null | password == "")
		{
			var passwordValidateTableCell = passwordTableRow.insertCell(-1);
			passwordValidateTableCell.className = "validate";
			passwordValidateTableCell.innerHTML = "Please enter a valid password";
			returnValue = false;
		}
		
		if(address == null || address == "")
		{
			var addressValidateTableCell = addressTableRow.insertCell(-1);
			addressValidateTableCell.className = "validate";
			addressValidateTableCell.innerHTML = "Please enter a Address";
			returnValue = false;
		}
		
		if(city == null || city == "")
		{
			var cityValidateTableCell = cityTableRow.insertCell(-1);
			cityValidateTableCell.className = "validate";
			cityValidateTableCell.innerHTML = "Please enter a City";
			returnValue = false;
		}
		
		if(state == null || state == "")
		{
			var stateValidateTableCell = stateTableRow.insertCell(-1);
			stateValidateTableCell.className = "validate";
			stateValidateTableCell.innerHTML = "Please enter a State";
			returnValue = false;
		}
		
		if(zip == null || zip == "")
		{
			var zipValidateTableCell = zipTableRow.insertCell(-1);
			zipValidateTableCell.className = "validate";
			zipValidateTableCell.innerHTML = "Please enter a Zip Code";
			returnValue = false;
		}
		
		return returnValue;
	}
	
	function pants_click()
	{
		window.location = 'pants.php';
	}

	function dateSelect()
	{
		var month = document.getElementById("month").value;
		var day = document.getElementById("day").value;
		var year = document.getElementById("year").value;
		
		document.getElementById("dob").value = month+'/'+day+'/'+year;
	}
	
	function loadHomePage()
	{
		window.location = "home.php";
	}
	
	function loadAdminPage()
	{
		var bodyIframe = parent.document.getElementById("bodyIframe");
		bodyIframe.src = "admin.php";
	}
	
	function onload_bodyIframe()
	{
		var headerIframe = parent.document.getElementById('headerIframe');
		headerIframe.src = 'loginformheader.php';
	}
	
	function loginStatusCheck(loginStatus)
	{
		if(loginStatus == 'fail')
		{
			var submitLogin = document.getElementById("submitLogin");
			var submitTableCell = document.getElementById("submitTableCell");
			
			var errorMessage =  document.createElement('label');
			errorMessage.className = 'validate';
			errorMessage.innerHTML = "Invalid Login";
			
			submitTableCell.insertBefore(errorMessage, submitLogin);
		}
	}
	

	function sweatshirts_click()
	{
		window.location = 'sweatshirts.php';
	}
	
	function tshirts_click()
	{
		window.location = 'tshirts.php';
	}
	
	function hats_click()
	{
		window.location = 'hats.php';
	}
	
	function displayImage(senderSrc)
	{
		var productDetails = document.getElementById("productDetails");
		productDetails.innerHTML = '';
		var image = document.createElement('img');
		image.src = senderSrc;
		productDetails.appendChild(image);
	}